package com.itheima.a13waitandnotify;

public class Cook extends Thread{
    @Override
    public void run() {
        while(true){
            synchronized (Desk.lock){
                if(Desk.count==0){
                    break;
                }else{
                    //判断桌子上是否有食物
                    if(Desk.foodFlag==1){
                        //如果有，就等待
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        //没有就制作
                        System.out.println("厨师做了一碗面条！！！");
                        Desk.foodFlag=1;
                        //叫醒消费者开吃
                        Desk.lock.notifyAll();
                    }
                }
            }
        }
    }
}
